package controllers

import (
	"net/http"

	"gitee.com/yanxingshuyuan/backend/server/models"
	"gitee.com/yanxingshuyuan/backend/server/repositories"
	"github.com/gin-gonic/gin"
)

type TagController struct {
	Repo *repositories.TagRepo
}

func NewTagController(r *repositories.TagRepo) *TagController {
	return &TagController{
		Repo: r,
	}
}

func (ctrl *TagController) ListNewsTags(c *gin.Context) {
	t := c.Query("t")
	tags := ctrl.Repo.ListNewsTags(t)
	c.JSON(http.StatusOK, tags)
}

func (ctrl *TagController) ListTags(c *gin.Context) {
	cat := c.Query("cat")
	kind := c.Query("kind")

	tags := ctrl.Repo.ListTags(cat, kind)
	c.JSON(http.StatusOK, tags)
}

func (ctrl *TagController) UpdateTags(c *gin.Context) {

	var tagsForm models.TagsForm

	c.ShouldBindJSON(&tagsForm)

	succ := ctrl.Repo.UpdateTags(tagsForm.Tags, tagsForm.Mid, models.MatTableMats)
	c.JSON(http.StatusOK, succ)
}
